package com.yuezhi.inv.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yuezhi.inv.entity.CommodityBill;
import com.yuezhi.inv.mapper.CommodityBillMapper;
import com.yuezhi.inv.service.CommodityBillService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author boys
 * @since 2020-12-21
 */
@Service
public class CommodityBillServiceImpl extends ServiceImpl<CommodityBillMapper, CommodityBill> implements CommodityBillService {

    // 根据模糊商品名查询出所有商品编号
    @Override
    public List<String> selectCommIdListByName(String commName) {
        QueryWrapper<CommodityBill> wrapper=new QueryWrapper<>();
        wrapper.like("comm_name",commName).select("id");
        List<CommodityBill> commList = baseMapper.selectList(wrapper);
        List<String> commIdList =new ArrayList<>();
        commList.forEach(commodityBill -> {
            commIdList.add(commodityBill.getId());
        });
        return commIdList;
    }

    // 根据模糊名字 查询所有相应的商品名称
    @Override
    public List<CommodityBill> selectCommList(String commName) {
        QueryWrapper<CommodityBill> wrapper =new QueryWrapper<>();
        wrapper.like("comm_name", commName);
        return baseMapper.selectList(wrapper);
    }
}
